package somsinfinal;

import java.awt.Image;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import javax.swing.ImageIcon;

/*
 * To change this template, choose Tools | Templates and open the template in
 * the editor.
 */
/**
 *
 * @Somsin Corp.
 */
public class Tank extends Vehicle {

    private int x, y, dx, dy;
    private int fuel;
    private int ammo;
    static ArrayList bullets;
    Image img;
    ImageIcon i = new ImageIcon("./images/yTank.png");
    ImageIcon tankU = new ImageIcon("./images/tankU.png");
    ImageIcon tankL = new ImageIcon("./images/tankL.png");
    ImageIcon tankD = new ImageIcon("./images/tankD.png");
    ImageIcon tankR = new ImageIcon("./images/tankR.png");

    public Tank() {

        img = tankR.getImage();
        x = 80;
        y = 175;
        ammo = 50;
        fuel = 500;
        bullets = new ArrayList();
    }

    public static ArrayList getBullets() {
        return bullets;
    }

    public void fire() {
        if (ammo > 0) {

            Bullet z = new Bullet(x, y);
            boolean add = bullets.add(z);
            ammo--;
        }
       
    }

  
    public void move() {
       x = x + dx;
        y = y + dy;


    }
//********************************************************************
    public void keyPressed(KeyEvent e) {
        int key = e.getKeyCode();
        //Up, Down, Left, Right           
      if(fuel>0){
        if (key == KeyEvent.VK_UP) {
            img = tankU.getImage();
            dy += -1;
            fuel -= 5;
        }
        if (key == KeyEvent.VK_DOWN) {
            img = tankD.getImage();
            dy += +1;
            fuel -= 5;
        }
        if (key == KeyEvent.VK_LEFT) {
            img = tankL.getImage();
            dx = -1;
            fuel -= 5;
        }
        if (key == KeyEvent.VK_RIGHT) {
            dx = +1;
            img = tankR.getImage();
            fuel -= 5;
        }
        if (key == KeyEvent.VK_W) {
            img = tankU.getImage();
            dy += -1;
            fuel -= 5;
        }
        if (key == KeyEvent.VK_Z) {
            img = tankD.getImage();
            dy += +1;
            fuel -= 5;
        }
        if (key == KeyEvent.VK_A) {
            img = tankL.getImage();
            dx = -1;
            fuel -= 5;
        }
        if (key == KeyEvent.VK_D) {
            dx = +1;
            img = tankR.getImage();
            fuel -= 5;
        }
      }
        if (key == KeyEvent.VK_SPACE) {
            fire();
        }
        if (key == KeyEvent.VK_F) {
            fuel = +500;
        }
  //      if (key == KeyEvent.VK_1) {
  //          fire1();
  //      }
    }

    public void keyReleased(KeyEvent e) {
        int key = e.getKeyCode();

        if (key == KeyEvent.VK_LEFT) {
            dx = 0;
        }
        if (key == KeyEvent.VK_RIGHT) {
            dx = 0;
        }
        if (key == KeyEvent.VK_UP) {
            dy = 0;
        }
        if (key == KeyEvent.VK_DOWN) {
            dy = 0;
        }
        if (key == KeyEvent.VK_A) {
            dx = 0;
        }
        if (key == KeyEvent.VK_D) {
            dx = 0;
        }
        if (key == KeyEvent.VK_W) {
            dy = 0;
        }
        if (key == KeyEvent.VK_Z) {
            dy = 0;
        }
        
        if (key == KeyEvent.VK_SPACE) {
            fire();

        }
        
        if (key == KeyEvent.VK_R) {
            ammo = 50;
        }

    }

    public Image getImage() {
        return img;
    }

    /**
     * @return the x
     */
    public int getX() {
        return x;
    }

    /**
     * @param x the x to set
     */
    public void setX(int x) {
        this.x = x;
    }

    /**
     * @return the y
     */
    public int getY() {
        return y;
    }

    /**
     * @param y the y to set
     */
    public void setY(int y) {
        this.y = y;
    }

    /**
     * @return the fuel
     */
    public int getFuel() {
        return fuel;
    }

    /**
     * @param fuel the fuel to set
     */
    public void setFuel(int fuel) {
        this.fuel = fuel;
    }

    /**
     * @return the ammo
     */
    public int getAmmo() {
        return ammo;
    }

    /**
     * @param ammo the ammo to set
     */
    public void setAmmo(int ammo) {
        this.ammo = ammo;
    }
}
